package zhouzhouyongche.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import zhouzhouyongche.model.Day;
import zhouzhouyongche.model.Minute;

@Repository
public class MinuteDao extends HibernateDao<Minute> {
	
	public Minute getOrAdd(int minute) {
		Minute result = null;
		String hql = "from Minute as m where m.minute = ?";
		Query q = getCurrentSession().createQuery(hql);
		q.setInteger(0, minute);
		List minuteList = q.list();
		if (minuteList.size() == 0) {
			Minute minuteObj = new Minute();
			minuteObj.setMinute(minute);
			this.save(minuteObj);
			
			String _hql = "from Minute as m where m.minute = ?";
			Query _q = getCurrentSession().createQuery(_hql);
			_q.setInteger(0, minute);
			result = (Minute)q.list().get(0);
		} else {
			result = (Minute)minuteList.get(0);
		}
		return result;
	}
	
}
